<template>
	<view class="news-page">
		<view v-for="item in newsList" :key="item._id" class="news-area" @click="toNewsDetail(item)">
			<view><img style="width: 100px;height: 80px;" :src="item.imgUrl" alt=""></view>
			<view style="flex:1;margin-left: 20rpx;position: relative;">
				<view class="text-title" style="font-size: 32rpx;margin-bottom: 20rpx;width: 100%;">{{item.title}}</view>
				<view style="font-size: 28rpx;position: absolute;bottom: 0;">
					发布时间：
					<uni-dateformat :threshold="[0, 0]" :date="item.created_date"></uni-dateformat>
					<!-- <text>{{item.created_by}}</text> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
			getDataFn
		} from '@/utils/baseFn.js';
	const db = uniCloud.database();
	const dbCmd = db.command;
	export default {
		data() {
			return {
				newsList: [],
				where: `"deleted_at"==null`,
				skipNum: 0
			}
		},
		created() {
			this.getNewsList()
		},
		mounted() {},
		methods: {
			getNewsList() {
				getDataFn('news-MGMT', this.where, this.skipNum,
					'title,introduce,annexId,deleted_at,created_date,updated_date,created_by').then(
					res => {
						const arr = []
						res.data.map(item => {
							const file = item.annexId.split(',')
							item.imgUrl = `${this.$baseImgUrl}${file[0]}`
							arr.push(item)
						})
						this.newsList = this.newsList.concat(arr)
						this.skipNum = this.newsList.length
					})
			},
			toNewsDetail(item) {
				uni.navigateTo({
					url: `newsDetail?id=${item._id}`
				});
			}
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			// this.skipNum = this.skipNum + 20
			this.getNewsList()
		}
	}
</script>

<style>
	.news-page {
		padding: 20rpx;
	}

	.news-area {
		display: flex;
		margin-top: 50rpx;
	}
	.text-title {
		font-size: 15px;
		font-family: 600;
		width: 70%;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
</style>
<style lang="scss">
</style>